<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width:100%;">
    <el-col :span="20">
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ nodeData.manager }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span>
              操作<i class="el-icon-arrow-down" />

            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { reqDelDepartment } from '@/api/departments'
export default {

  props: {
    nodeData: {
      type: Object,
      required: true
    },
    // 是否根节点
    root: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // del() {
    //   console.log('没了')
    // }
    handleCommand(type) {
      // console.log(222, type)
      if (type === 'add') {
        console.log('添加')
        // 新增弹窗显示
        this.$emit('add-depts', this.nodeData)
      }
      if (type === 'edit') {
        console.log('编辑')
      }
      if (type === 'del') {
        console.log('删除')
        this.$confirm('此操作将永久删除该部门, 继续么?', '温馨提示').then(async() => {
          console.log('确认')
          // 调用接口
          const res = await reqDelDepartment(this.nodeData.id)
          console.log(res)
          // 通知父组件更新
          this.$emit('del-depts')
        }).catch(() => {
          console.log('取消')
        })
      }
    }
  }
}
</script>

<style>

</style>
